﻿using System;

class Employee
{
    // 使用自动属性和初始化器
    public int Id { get; init; }
    public string Name { get; init; }
    public int Age { get; set; }
    public string Department { get; set; }
    public decimal Salary { get; set; }
    public DateTime HireDate { get; init; }
    public string Position { get; set; }
    public string Email { get; set; }

    // 主构造方法（C# 9.0+）
    public Employee(int id, string name, string department, decimal salary)
    {
        Id = id;
        Name = name ?? throw new ArgumentNullException(nameof(name));
        Department = department;
        Salary = salary;
        HireDate = DateTime.Today;
        Position = "员工";
        Email = $"{name}@company.com";
    }

    // 显示信息
    public void DisplayInfo() => Console.WriteLine(this);

    public override string ToString() =>
        $"""
         员工信息：
        ================
        ID: {Id}
        姓名: {Name}
        年龄: {Age}
        部门: {Department}
        职位: {Position}
        工资: {Salary:C}
        入职日期: {HireDate:yyyy-MM-dd}
        邮箱: {Email}
        工龄: {(DateTime.Now - HireDate).Days / 365} 年
        ================
        """;
}

class Program
{
    static void Main()
    {
        // 使用对象初始化器
        var emp = new Employee(1001, "张三", "技术部", 15000m)
        {
            Age = 28,
            Position = "工程师",
            Email = "zhang@company.com"
        };

        emp.DisplayInfo();
    }
}